package com.yohann.designPattern.iterator.iterator;

import com.yohann.designPattern.iterator.department.Department;

import java.util.Iterator;
import java.util.List;

/**
 * <p>
 * 信息学院迭代器
 * </p>
 *
 * @author Yohann
 * @since 2021/2/12 16:01
 */
public class InfoCollegeIterator implements Iterator {
    private List<Department> departments;
    private int index = -1;

    public InfoCollegeIterator(List<Department> departments) {
        this.departments = departments;
    }

    @Override
    public boolean hasNext() {
        if (index >= departments.size() - 1) {
            return false;
        } else {
            index += 1;
            return true;
        }
    }

    @Override
    public Object next() {
        return departments.get(index);
    }
}